package com.spring.demo1;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class MainApp {

	/**
	 * Spring bean 的初始化 销毁回掉，单例or多实例
	 */
	public void testDemo1(){
		//ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");
		//ApplicationContext context = new FileSystemXmlApplicationContext("src/test/resources/bean.xml");
		AbstractApplicationContext context = new FileSystemXmlApplicationContext("src/test/resources/bean.xml");
		HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
		HelloWorld obj2 = (HelloWorld) context.getBean("helloWorld");
		obj.setMessage("aa");
		System.out.println(obj.getMessage());
		//System.out.println(obj2.getMessage());
		//System.out.println("2个对象是否相等："+(obj == obj2));
		context.registerShutdownHook();//AbstractApplicationContext中才有此销毁方法
	}
	public static void main(String[] args) {
		new MainApp().testDemo1();
	}
}
